//把不同的工作放到不同的方法中
//this指向

class ChinaMap {
    constructor() {
        console.log('实例化');
        //统一方案
        this.cube=null; // 属性
        this.init(); //执行流程的管理方法
    }
    init() {
        // 三个对象实例
        this.scene = new THREE.Scene()
        this.setCamera()
        this.setRenderer()
        const geometry = new THREE.BoxGeometry()
        const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 })
        this.cube = new THREE.Mesh(geometry, material)
        this.scene.add(this.cube)
        this.render();
        this.animate();
        var controller=new THREE.OrbitControls(this.camera,this.renderer.domElement);

    }
    setCamera() {
        this.camera = new THREE.PerspectiveCamera(
            75,
            window.innerWidth / window.innerHeight,
            0.1,
            1000
          )
          this.camera.position.z = 5;
          this.camera.position.x=0.5;
          this.camera.position.y=0.5;
    }
    setRenderer() {
        this.renderer = new THREE.WebGLRenderer()
        this.renderer.setSize(window.innerWidth, window.innerHeight)
        document.body.appendChild(this.renderer.domElement)
    }
    render() {
        this.renderer.render(this.scene, this.camera)
    }
    animate(){
        requestAnimationFrame(this.animate.bind(this))
        this.cube.rotation.x += 0.01
        this.cube.rotation.y += 0.01
        this.render()

    }
}
